Reprence Html CSS javascript PHP MySQL Bootsrap

The MySQL GROUP BY Statement

The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country".

The GROUP BY statement is often used with aggregate functions COUNT(), MAX(), MIN(), SUM(), AVG() to group the result-set by one or more columns.

GROUP BY Syntax

109

Demo Database

Below is a selection from the "Customers" table in the Northwind sample database:

110

MySQL GROUP BY Examples

The following SQL statement lists the number of customers in each country:

The following SQL statement lists the number of customers in each country, sorted high to low:



Demo Database

Below is a selection from the "Orders" table in the Northwind sample database:

111

And a selection from the "Shippers" table:

112

GROUP BY With JOIN Example

The following SQL statement lists the number of orders sent by each shipper: